import logger from '../core/logger';
import apiInfo from './core/apiInfo';
import apiProvider from './core/apiProvider';
import { clientBase } from './core/clientBase';
import returnModel from '../model/common/returnModel';
import { emptyData } from '../model/common/emptyData';

class seasonClient extends clientBase {
  constructor() {
    super();
  }

  getCondition(seasonType: number): Promise<returnModel<emptyData>> {
    return new Promise((resolve) => {
      let info = new apiInfo("https://api.bilibili.com/pgc/season/index/condition", `season_type=${seasonType}&type=0`);
      info.buildVer = apiProvider.Build4;
      this.client.getResult(info).then((res) => {
        try {
          if (res.code == 0)
            resolve(this.buildSuccessResult<emptyData>(res));
          else
            resolve(this.buildFailedResult<emptyData>(res.message));
        } catch (e) {
          logger.error(e);
          resolve(this.buildExceptionResult<emptyData>(e));
        }
      });
    });
  }

  getResult(condition: string, page: number, seasonType: number): Promise<returnModel<emptyData>> {
    return new Promise((resolve) => {
      let info = new apiInfo("https://api.bilibili.com/pgc/season/index/result", `${condition}&page=${page}&pagesize=20&season_type=${seasonType}&type=0`);
      info.buildVer = apiProvider.Build4;
      this.client.getResult(info).then((res) => {
        try {
          if (res.code == 0)
            resolve(this.buildSuccessResult<emptyData>(res));
          else
            resolve(this.buildFailedResult<emptyData>(res.message));
        } catch (e) {
          logger.error(e);
          resolve(this.buildExceptionResult<emptyData>(e));
        }
      });
    });
  }
}
export default new seasonClient();